import ZIcon from "@/components/Icon/ZIcon.vue";
import { NButton, NPopconfirm, NSpace } from "naive-ui";

export const genDeleteAction = (deleteApi: any, fixed: any = undefined) => {
  const config = {
    fixed,
    render({ rowData, methods }: any) {
      return (
        <NPopconfirm
          onPositiveClick={async () => {
            await deleteApi(rowData.id);
            methods.reload();
          }}
        >
          {{
            default: () => "确认删除吗?",
            trigger: () => (
              <NButton quaternary type="error">
                <ZIcon name="DeleteIcon"> </ZIcon>
              </NButton>
            ),
          }}
        </NPopconfirm>
      );
    },
  };
  return config;
};

export const genBasicActions = (
  deleteApi: any,
  editApi: any,
  fixed: any = undefined
) => {
  const config = {
    fixed,
    render({ rowData, methods }: any) {
      return (
        <NSpace>
          <NButton
            quaternary
            type="primary"
            onClick={async () => {
              await editApi({ rowData });
            }}
          >
            <ZIcon name="EditIcon"> </ZIcon>
          </NButton>

          <NPopconfirm
            onPositiveClick={async () => {
              await deleteApi(rowData.id);
              methods.reload();
            }}
          >
            {{
              default: () => "确认删除吗?",
              trigger: () => (
                <NButton quaternary type="error">
                  <ZIcon name="DeleteIcon"> </ZIcon>
                </NButton>
              ),
            }}
          </NPopconfirm>
        </NSpace>
      );
    },
  };
  return config;
};
